;; -*- Emacs-Lisp -*-
;; Time-stamp: <2010-12-01 11:57:41 Wednesday by taoshanwen>

(require 'util)
(require 'emaci)

(defun emaci-settings ()
  "settings for `emaci'."
  (setq emaci-brief-key-defs
        (append emaci-brief-key-defs
                `(("]" goto-paren))))
  (emaci-bind-brief-keys)
  
(eal-define-keys-commonly
 emaci-mode-map
 `(
   ;; ("a"       undefined)
   ("b"       undefined)
   ("c"       undefined)
   ;; ("d"       undefined)
   ;; ("e"       undefined)
   ;; ("f"       undefined)
   ;; ("g"       undefined)
   ;; ("h"       undefined)
   ;; ("i"       undefined)
   ;; ("j"       undefined)
   ;; ("k"       undefined)
   ;; ("l"       undefined)
   ("m"       undefined)
   ("n"       undefined)
   ;; ("o"       undefined)
   ("p"       undefined)
   ("q"       undefined)
   ;; ("r"       undefined)
   ;; ("s"       undefined)
   ("t"       undefined)
   ("u"       undefined)
   ("v"       undefined)
   ("w"       undefined)
   ("x"       undefined)
   ;; ("y"       undefined)
   ("z"       undefined)
   ("A"       undefined)
   ("B"       undefined)
   ("C"       undefined)
   ("D"       undefined)
   ("E"       undefined)
   ("F"       undefined)
   ("G"       undefined)
   ("H"       undefined)
   ("I"       undefined)
   ("J"       undefined)
   ("K"       undefined)
   ("L"       undefined)
   ("M"       undefined)
   ("N"       undefined)
   ("O"       undefined)
   ("P"       undefined)
   ("Q"       undefined)
   ("R"       undefined)
   ("S"       undefined)
   ("T"       undefined)
   ("U"       undefined)
   ("V"       undefined)
   ("W"       undefined)
   ("X"       undefined)
   ("Y"       undefined)
   ("Z"       undefined)
   ;; ("1"       undefined)
   ;; ("2"       undefined)
   ;; ("3"       undefined)
   ;; ("4"       undefined)
   ;; ("5"       undefined)
   ;; ("6"       undefined)
   ;; ("7"       undefined)
   ;; ("8"       undefined)
   ;; ("9"       undefined)
   ;; ("0"       undefined)
   ("!"       undefined)
   ("@"       undefined)
   ("#"       undefined)
   ("$"       undefined)
   ("%"       undefined)
   ("^"       undefined)
   ("&"       undefined)
   ("*"       undefined)
   ("("       undefined)
   (")"       undefined)
   ("`"       undefined)
   ("-"       undefined)
   ("="       undefined)
   ("["       undefined)
   ("]"       undefined)
   ;; ("'"       undefined)
   ;; (","       undefined)
   ("."       undefined)
   ("/"       undefined)
   ("~"       undefined)
   (":"       undefined)
   ("<"       undefined)
   (">"       undefined)
   ;; ("?"       undefined)
   (";"       undefined)
   ("\""      undefined)
   ("\\"      undefined)
   ("|"       undefined)
   ("a"       move-beginning-of-line)
   ("e"       move-end-of-line)
   ("j"       next-line)
   ("k"       previous-line)
   ("h"       backward-char)
   ("l"       forward-char)
   ;; ("SPC"     self-insert-command)
   ("SPC"       scroll-up)
   ("n"       scroll-up)
   ("u"       scroll-down)
   ;; ("v"       View-scroll-half-page-forward)
   ;; ("w"       View-scroll-half-page-backward)
   ("g"       emaci-g)
   ("G"       end-of-buffer)
   ("L"       forward-word)
   ("H"       backward-word)
   ("o"       ido-find-file)
   (";"       ido-switch-buffer)
   ("\""      ibuffer)
   ;; ("q"       emaci-q)
   ("i"       emaci-q)
   ("1"       delete-other-windows)
   ("-"       split-window-vertically)
   ("\\"       split-window-horizontally)
   ("q"       delete-window)
   ("s"       save-buffer)
   (","       ace-jump-mode)
   ("R"       org-capture)
   ("r"       query-replace)
   ("]"       goto-paren)
   ("?"       help-for-help-internal)
   ("m"       set-mark-command)
   ("M"       exchange-point-and-mark)
   ("f"       find-tag)
   ("F"       pop-tag-mark)
   ("'"       other-window)
   ;; Edit commands
   ("W"       kill-region)
   ("w"       my-kill-ring-save)
   ("d"       delete-char)
   ("v"       yank)
   ("y"       yank)
   ("C"       kill-buffer)
   ("c"       my-kill-ring-save)
   ("<"       recent-jump-jump-backward)
   (">"       recent-jump-jump-forward)
   ("/"       goto-last-change)
   ("t"       emaci-replace-char)
   ("."       jump-char-forward)
   ("S" save-some-buffers)
   )))


(define-key emaci-mode-map "2" 'digit-argument)
(define-key emaci-mode-map (kbd "<left>") 'windmove-left)
(define-key emaci-mode-map (kbd "<right>") 'windmove-right)
(define-key emaci-mode-map (kbd "<up>") 'windmove-up)
(define-key emaci-mode-map (kbd "<down>") 'windmove-down)
(define-key emaci-mode-map "3" 'digit-argument)
(define-key emaci-mode-map "4" 'digit-argument)
(define-key emaci-mode-map "5" 'digit-argument)
(define-key emaci-mode-map "6" 'digit-argument)
(define-key emaci-mode-map "7" 'digit-argument)
(define-key emaci-mode-map "8" 'digit-argument)
(define-key emaci-mode-map "9" 'digit-argument)

(eval-after-load "emaci"
  `(emaci-settings))

(defun my-kill-ring-save ()
        (interactive)
        (if (equal mark-active nil) 
	    (kill-ring-save (point) (line-end-position)) 
	  (kill-ring-save (point) (mark))))


(defun emaci-replace-char (s)
  "preplace current char"
  (interactive "sinsert string: ")
  (delete-char 1)
  (insert s))

(add-hook 'fortran-mode-hook 'emaci-mode-on)
(add-hook 'f90-mode-hook 'emaci-mode-on)
(add-hook 'emacs-lisp-mode-hook 'emaci-mode-on)
(provide 'emaci-settings)
